package com.cc.blog.admin.controller;

import com.cc.blog.admin.domain.dto.*;
import com.cc.blog.admin.service.AdminWikiService;
import com.cc.blog.common.annotation.ApiOperationLog;
import com.cc.blog.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Admin 知识库模块
 * @author cc
 * @date 2024/10/3 10:49
 */
@RestController
@RequestMapping("/admin/wiki")
@Api(tags = "Admin 知识库模块")
@AllArgsConstructor
public class AdminWikiController {

    private final AdminWikiService wikiService;

    @PostMapping("/add")
    @ApiOperation(value = "新增知识库")
    @ApiOperationLog(description = "新增知识库")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result addWiki(@RequestBody @Validated AddWikiReqDTO addWikiReqDTO) {
        return wikiService.addWiki(addWikiReqDTO);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "知识库删除")
    @ApiOperationLog(description = "知识库删除")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result deleteWiki(@RequestBody @Validated DeleteWikiReqDTO deleteWikiReqDTO) {
        return wikiService.deleteWiki(deleteWikiReqDTO);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询知识库分页数据")
    @ApiOperationLog(description = "查询知识库分页数据")
    public Result findWikiPageList(@RequestBody @Validated FindWikiPageListReqDTO findWikiPageListReqDTO) {
        return wikiService.findWikiPageList(findWikiPageListReqDTO);
    }

    @PostMapping("/isTop/update")
    @ApiOperation(value = "更新知识库置顶状态")
    @ApiOperationLog(description = "更新知识库置顶状态")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result updateWikiIsTop(@RequestBody @Validated UpdateWikiIsTopReqDTO updateWikiIsTopReqDTO) {
        return wikiService.updateWikiIsTop(updateWikiIsTopReqDTO);
    }

    @PostMapping("/isPublish/update")
    @ApiOperation(value = "更新知识库发布状态")
    @ApiOperationLog(description = "更新知识库发布状态")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result updateWikiIsPublish(@RequestBody @Validated UpdateWikiIsPublishReqDTO updateWikiIsPublishReqDTO) {
        return wikiService.updateWikiIsPublish(updateWikiIsPublishReqDTO);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新知识库")
    @ApiOperationLog(description = "更新知识库")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result updateWiki(@RequestBody @Validated UpdateWikiReqDTO updateWikiReqDTO) {
        return wikiService.updateWiki(updateWikiReqDTO);
    }

    @PostMapping("/catalog/list")
    @ApiOperation(value = "查询知识库目录数据")
    @ApiOperationLog(description = "查询知识库目录数据")
    public Result findWikiCatalogList(@RequestBody @Validated FindWikiCatalogListReqDTO findWikiCatalogListReqDTO) {
        return wikiService.findWikiCatalogList(findWikiCatalogListReqDTO);
    }

    @PostMapping("/catalog/update")
    @ApiOperation(value = "更新知识库目录")
    @ApiOperationLog(description = "更新知识库目录")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result updateWikiCatalogs(@RequestBody @Validated UpdateWikiCatalogReqDTO updateWikiCatalogsReqDTO) {
        return wikiService.updateWikiCatalogs(updateWikiCatalogsReqDTO);
    }
}
